package com.xlf.service.base.controller.client;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xlf.common.core.annotation.Anonymous;
import com.xlf.common.core.annotation.RepeatSubmit;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.service.base.pojo.dto.JudgeListReqDTO;
import com.xlf.service.base.pojo.dto.RanksDTO;
import com.xlf.service.base.pojo.dto.SubmitJudgeDTO;
import com.xlf.service.base.pojo.dto.TestJudgeDTO;
import com.xlf.service.base.pojo.vo.JudgeDetailVO;
import com.xlf.service.base.pojo.vo.ProblemDetailVO;
import com.xlf.service.base.service.JudgeService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/10/5 21:34
 * @Description: TODO 判题模块
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/judge")
public class JudgeController extends BaseController {

    @Autowired
    JudgeService judgeService;

    /**
     * 获取评测列表
     * @param judgeListReqDTO
     * @return
     */
    @Anonymous
    @PostMapping("/list")
    public AjaxResult getJudgeList(@RequestBody JudgeListReqDTO judgeListReqDTO) {
        return success(judgeService.getJudgeList(judgeListReqDTO));
    }

    /**
     * 获取评测详情
     * @param id
     * @return
     */
    @Anonymous
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable(value = "id") Long id){
        return success(judgeService.getJudge(id));
    }

    /**
     * 提交测试用例
     * @param testJudgeDto
     * @return
     */
    @RepeatSubmit(interval = 3000,message = "操作频繁，稍后重试！",ignoreParams = true)
    @PostMapping(value = "/submit-problem-test-judge")
    public AjaxResult submitTestJudge(@RequestBody TestJudgeDTO testJudgeDto) {
        return success("提交成功",judgeService.submitTestJudge(testJudgeDto));
    }


    /**
     * 判题入口
     * @param judgeDto
     * @return
     */
    @RepeatSubmit(interval = 5000,message = "操作频繁，稍后重试！",ignoreParams = true)
    @RequestMapping(value = "/submit-problem-judge", method = RequestMethod.POST)
    public AjaxResult submitProblemJudge(@RequestBody SubmitJudgeDTO judgeDto) {
        return success("提交成功",judgeService.submitProblemJudge(judgeDto));
    }

    /**
     * 获取用例测试结果
     * @param testJudgeKey
     * @return
     */
    @GetMapping("/get-test-judge-result")
    public AjaxResult getTestJudgeResult(@RequestParam("testJudgeKey") String testJudgeKey) {
        return success(judgeService.getTestJudgeResult(testJudgeKey));
    }

    /**
     * @Description 获取单个提交记录的详情
     */
    @Anonymous
    @GetMapping("/get-submission-detail")
    public AjaxResult getSubmission(@RequestParam(value = "judgeId", required = true) Long judgeId) {
        return success(judgeService.getSubmission(judgeId));
    }




    /**
     * @Description 获取排行榜
     */
    @Anonymous
    @GetMapping("/getRanks")
    public AjaxResult getRanks() {
        return success(judgeService.getRanks());
    }



}
